@extends('admin.public.admin')
@section('main')

<!-- 上传的 -->
<link rel="stylesheet" type="text/css" href="/up/uploadify.css">

<!-- <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script> -->
<script type="text/javascript" src="/style/admin/js/goods/jquery-1.7.2.min.js"></script>

<script type="text/javascript" src="/up/jquery.uploadify.min.js"></script>

<!-- 百度 -->
<script type="text/javascript" charset="utf-8" src="/baidu/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/baidu/ueditor.all.min.js"> </script>
<!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="/baidu/lang/zh-cn/zh-cn.js"></script>
<!-- 内容 -->
<div class="mws-panel grid_8">
    <div class="mws-panel-header">
         <span>修改商品</span>
    </div>

      <div class="mws-panel-body no-padding">

           <form class="mws-form" action="/admin/goods/{{$data['id']}}" method="post" enctype='multipart/form-data'>
           {{csrf_field()}}
        <input type="hidden" value="PUT" name="_method">
            <input type="hidden" name='tid' value="{{$types['id']}}"
              <div class="mws-form-inline">
				<div class="mws-form-row">
                    <label class="mws-form-label">所属分类</label>
                    <div class="mws-form-item">
                                
									      <input type="text" disabled value="{{$types['typename']}}" >  

                    </div>
                </div>
		


		   <!-- <div class="div_title"><span>产品规格</span></div>

                    <div class="div_contentlist">
                        <ul class="Father_Title"><li id="yname"></li></ul>
                        <ul class="Father_Item0">
                            <li class="li_width"><label><input id="Checkbox3" type="checkbox" class="chcBox_Width" value="军绿色" />军绿色<span class="li_empty"  contentEditable="true"></span></label></li>
                        </ul>
                        <br/>
                    </div> -->


						
						

                     <div class="mws-form-row">
                          <label class="mws-form-label">商品名称</label>
                          <div class="mws-form-item">
                               <input type="text" class="small" name="goodsname" value="{{$data['goodsname']}}" >
                          </div>
                     </div>

                  
                     <div class="mws-form-row">
                          <label class="mws-form-label">商品标题</label>
                          <div class="mws-form-item">
                               <input type="text" class="small" name="title"  value="{{$data['title']}}">
                          </div>
                     </div>
	
                     <div class="mws-form-row">
                          <label class="mws-form-label">商品价格</label>
                          <div class="mws-form-item">
                               <input type="number" class="small" name="price"  value="{{$data['price']}}">
                          </div>
                     </div>

                     <div class="mws-form-row">
                          <label class="mws-form-label">商品库存</label>
                          <div class="mws-form-item">
                               <input type="number" class="small" name="num"  value="{{$data['num']}}">
                          </div>
                     </div>
                    
                    
                    <div class="mws-form-row">
            						<label class="mws-form-label">商品封面图片</label>

            						<div class="mws-form-item">
            							   <input type="file" name="" id="uploads">
                      	</div>

            						<div id="main" class="mws-form-item">
            							 <img width="200px"  src="{{$data['img']}}" alt="">
            						</div>
            						<input type="hidden" name="img" id="imgs">
                  </div>
             
          				
					
          <div class="mws-form-row">
                <label class="mws-form-label">商品多图</label>
                    
                      <div class="mws-form-item">
                           <input type="file" name="" id="uploads1">
                       </div>
                  @foreach($tupian as $tu)
                      <div id="main1" class="mws-form-item">
                         <img width="200px"  src="{{$tu['imgs']}}" alt="">
                      </div>
                  @endforeach
                   <input type="hidden" name="imgs" id="imgs1">
            </div>
				
				  <div class="mws-form-row">
                  <label class="mws-form-label">商品简介</label>
                  <div class="mws-form-item">
                      <script id="editor" type="text/plain" name="text" style="width:100%;height:300px;">{!!$data['text']!!}</script>
                  </div>
           </div>

                 <div class="mws-form-row">
                      <label class="mws-form-label">商品配置</label>
                      <div class="mws-form-item">
							<script id="editor1" type="text/plain" name="config" style="width:100%;height:300px;">{!!$data['config']!!}</script>
                      </div>
                 </div>
            
                @if($data['is_on_sale'])
                      <div class="mws-form-row">
                          <label class="mws-form-label">上架</label>
                          <div class="mws-form-item clearfix">
                               <ul class="mws-form-list inline">
                                    <li><input type="radio" name="is_on_sale" value="1"  checked> <label>上架</label></li>
                                    <li><input type="radio" name="is_on_sale" value="0"> <label>不上架</label></li>                                       
                               </ul>
                          </div>
                     </div>
                  @else
		
                     <div class="mws-form-row">
                          <label class="mws-form-label">上架</label>
                          <div class="mws-form-item clearfix">
                               <ul class="mws-form-list inline">
                                    <li><input type="radio" name="is_on_sale" value="1"  > <label>上架</label></li>
                                    <li><input type="radio" name="is_on_sale" value="0" checked> <label>不上架</label></li>                                       
                               </ul>
                          </div>
                     </div>
                  @endif
                </div>
                <div class="mws-button-row">
                     <input type="submit" value="修改" class="btn btn-success">
                     <input type="button" class="btn btn-danger" onclick="history.go(-1)" value="返回">

                </div>
           </form>
      </div>         
  </div>

<script>
	// 当所有HTML代码都加载完毕
	$(function() {
		// 商品详情的百度编辑器调用
		var ue = UE.getEditor('editor');
		var ue1 = UE.getEditor('editor1');
		// 声明字符串

		var imgs='';
		// 使用 uploadify 插件
        $('#uploads').uploadify({
        	// 设置文本
            'buttonText' : '图片上传',
            // 设置文件传输数据
            'formData'     : {
            	'_token':'{{ csrf_token() }}',
            	'files':'goods',
                
            },
            // 上传的flash动画
            'swf'      : "/up/uploadify.swf",
            // 文件上传的地址
            'uploader' : "/admin/shangchuan",
            // 当文件上传成功
            'onUploadSuccess' : function(file, data, response) {

            	// 拼接图片
            	imgs="<img width='200px'  src='/Uploads/goods/"+data+"'>";
            	// 展示图片
            	$("#main").html(imgs);
            	// 隐藏传递数据
            	$("#imgs").val(data);
               
            }
        });

        // 商品的多图片上传
		var imgs1='';

		var arr=[];
		// 使用 uploadify 插件
        $('#uploads1').uploadify({

        	// 设置文本
            'buttonText' : '多图片上传',
            // 设置文件传输数据
            'formData'     : {
            	'_token':'{{ csrf_token() }}',
            	'files':'goods',
                
            },

            // 上传的flash动画
            'swf'      : "/up/uploadify.swf",
            // 文件上传的地址
            'uploader' : "/admin/shangchuan",

            // 当文件上传成功
            'onUploadSuccess' : function(file, data, response) {
              //移除原图片
               $("#main1 img").remove(); 
            	// 拼接图片
            	imgs1+="<img width='200px'  src='/Uploads/goods/"+data+"'>";
          
            	arr.push(data);
            	// 展示图片
            	$("#main1").html(imgs1);
            	// 隐藏传递数据
            	$("#imgs1").val(arr.join(','));
               
            }
        });
    });






// ajax权限

  $("#attr").change(function(){

  	   // 发送ajax请求
     var tid=$("#attr").val();
   
     $.post("/admin/goods/attr",{tid:tid,"_method":'post','_token':'{{csrf_token()}}'},function(data){
     	var obj=JSON.parse(data);
     	// console.log(data);
     	// console.log(obj[0].tagname);

     	$("#yname").html(obj[0].tagname);


     	for(i=0;i<obj.lenght;i++){
       
        	// $("#yname").attr("value",obj[i].tagname);
        	
        	$("#yname").html(obj[0].tagname);
        	
   			}

      });

  });


</script>
@endsection